home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include "stdg.h"
-
- /* Press space repeatedly to see a demo of the library's features */
-
- #define NORMAL_TEST 1
- #define USE_RESOURCES 0
-
- void cont(char *);
- void putstring(char *);
-
- unsigned char arrowbits[] =
- {0x00, 0x00, 0x7F, 0xC0, 0x7F, 0x00, 0x7C, 0x00,
- 0x7E, 0x00, 0x7F, 0x00, 0x6F, 0x80, 0x67, 0xC0,
- 0x43, 0xE0, 0x41, 0xF0, 0x00, 0xF8, 0x00, 0x7C,
- 0x00, 0x3E, 0x00, 0x1C, 0x00, 0x08, 0x00, 0x00};
-
- char *colornames[] = { "Black", "Blue", "Red", "Magenta",
- "DkGrey", "Grey", "LtGrey", "Green", "Cyan", "Yellow", "White" };
- pixval colordefs[] = { BLACK, BLUE, RED, MAGENTA,
- DKGREY, GREY, LTGREY, GREEN, CYAN, YELLOW, WHITE };
-
- #define Ncol (sizeof(colordefs)/sizeof(pixval))
-
- window *w; /* main window */
-
- int main(int argc, char **argv)
- {
- point p1,p2,p3;
- mouse m;
- int r,rx,ry;
- int n, i;
- char *p, buf[200];
- bitmap *bm, *bm2;
-
- ginit("Tester", NULL, NULL);
- w = new_window("Tester", rect(0,0,0,0),
- Titlebar+Resize+Maximize);
- show_window(w);
-
- p1 = addp(w->b->r.min, pt(15,15));
- p2 = subp(w->b->r.max, pt(15,15));
-
- #if NORMAL_TEST
-
- draw_line(w->b, p1, p2, BLACK);
-
- cont("draw_point");
- draw_point(w->b, p1, BLACK);
-
- cont("draw_rect");
- draw_rect(w->b, insetr(w->b->r, 4), 2, GREY);
-
- cont("draw_circle");
- p3 = divp(addp(p1,p2),2);
- rx = p3.x - p1.x;
- ry = p3.y - p1.y;
- r = (rx < ry)? rx : ry;
- draw_circle(w->b, p3, r, BLACK);
-
- cont("fill_circle");
- fill_circle(w->b, p3, r, GREY);
-
- cont("draw_ellipse");
- draw_ellipse(w->b, p3, r, r/2, BLACK);
-
- cont("draw_arc");
- draw_arc(w->b, p3, pt(p3.x+r,p3.y), pt(p3.x+r/2,p3.y-(int)(r*.866)), BLACK);
-
- cont("color");
- p3 = p1;
- rx *= 2;
- ry *= 2;
- for(i = 0; i<Ncol; i++) {
- fill_rect(w->b, rpt(p3,addp(p3,pt(rx,ry/Ncol))), colordefs[i]);
- draw_string(w->b, addp(p3,pt(15,5)), sys_font,
- colornames[i], colordefs[Ncol-i-1]);
- p3.y += ry/Ncol;
- }
-
- #endif
-
- #if USE_RESOURCES
-
- cont("get_bitmap, draw_rect, and bit_copy(S)");
- p3 = p1;
-
- set_cursor(get_cursor("Hand"));
-
- bm = get_bitmap("Circles", 1);
- draw_rect(w->b, raddp(bm->r, p3), -2, BLACK);
- bit_copy(w->b, p3, bm, bm->r, S);
- del_bitmap(bm);
-
- p3.x += 48;
-
- bm = get_bitmap("Circles", 4);
- draw_rect(w->b, raddp(bm->r, p3), -2, BLACK);
- bit_copy(w->b, p3, bm, bm->r, S);
- del_bitmap(bm);
-
- p3.x += 48;
-
- bm = get_bitmap("Circles", 8);
- draw_rect(w->b, raddp(bm->r, p3), -2, BLACK);
- bit_copy(w->b, p3, bm, bm->r, S);
- del_bitmap(bm);
-
- p3.x += 48;
-
- bm = get_bitmap("Circles", 0);
- draw_rect(w->b, raddp(bm->r, p3), -2, BLACK);
- bit_copy(w->b, p3, bm, bm->r, S);
- del_bitmap(bm);
-
- p3 = p1;
- p3.y += 48;
-
- bm = get_bitmap("Small Circles", 1);
- draw_rect(w->b, raddp(bm->r, p3), -2, BLACK);
- bit_copy(w->b, p3, bm, bm->r, S);
- del_bitmap(bm);
-
- p3.x += 48;
-
- bm = get_bitmap("Small Circles", 4);
- draw_rect(w->b, raddp(bm->r, p3), -2, BLACK);
- bit_copy(w->b, p3, bm, bm->r, S);
- del_bitmap(bm);
-
- p3.x += 48;
-
- bm = get_bitmap("Small Circles", 8);
- draw_rect(w->b, raddp(bm->r, p3), -2, BLACK);
- bit_copy(w->b, p3, bm, bm->r, S);
- del_bitmap(bm);
-
- p3.x += 48;
-
- bm = get_bitmap("Small Circles", 0);
- draw_rect(w->b, rdiag(p3.x, p3.y, 16, 16), -2, BLACK);
- bit_copy(w->b, p3, bm, bm->r, S);
- del_bitmap(bm);
-
- bm = get_bitmap("Colour PICT", 0);
- bit_copy(w->b, addp(p1,pt(0,96)), bm, bm->r, S);
- del_bitmap(bm);
-
- #endif /* USE_RESOURCES */
-
- cont("mouse track (button 1)");
- do{
- m = get_mouse(w);
- } while(!(m.buttons&1));
- while(m.buttons&1){
- draw_point(w->b, m.xy, BLACK);
- gflush();
- m = get_mouse(w);
- }
- set_cursor(NULL);
-
- cont("keyboard (end with \\n)");
- for (p = buf; (*p = get_key(w)) != '\n';) {
- if (*p == '\b') {
- p -= 2;
- if (p < buf)
- p = buf-1;
- }
- p++;
- *p = '\0';
- putstring(buf);
- }
-
- cont("done");
- hide_window(w);
-
- return 0;
- }
-
- void putstring(char *buf)
- {
- point p;
- static int jmax = 0, l;
-
- p = addp(w->b->r.min, pt(20,20));
- fill_rect(w->b, rect(p.x, p.y, p.x+jmax, p.y+sys_font->height*2), WHITE);
- draw_string(w->b, p, sys_font, buf, BLACK);
- draw_string(w->b, pt(p.x,p.y+sys_font->height), sys_font, buf, GREY);
- if ((l = strwidth(sys_font, buf)) > jmax)
- jmax = l;
- gflush();
- }
-
- void cont(char *msg)
- {
- point mp;
- mouse m;
-
- gflush();
- while(!can_key(w))
- continue;
- get_key(w);
-
- fill_rect(w->b, w->b->r, WHITE);
- mp = addp(w->b->r.min, pt(20,20));
- draw_string(w->b, mp, fixed_font, msg, BLACK);
- gflush();
-
- while(!can_key(w))
- continue;
- get_key(w);
-
- fill_rect(w->b, w->b->r, WHITE);
- gflush();
- }
-